package logic;

import java.util.Iterator;
import java.util.List;

import data.JDBCProductDAO;

public class ProductList {
	
	private static ProductList prodList;
	private List<Product> lp;
	
	public static synchronized ProductList getInstance(){
		if(prodList == null){
			prodList = new ProductList();
		}
		return prodList;
	}
	
	public ProductList(){
		lp = (new JDBCProductDAO()).selectActiveProducts();
	}
	
	public List<Product> getProducts(){
		return lp;
	}
	
	 public Product getProduct(String prodId) {
	        Product result = null;
	        for (Iterator<Product> iter = lp.iterator(); iter.hasNext();) {
	            Product d = (Product) iter.next();
	            if (d.getId().compareTo(prodId) == 0) {
	                result = d;
	            }
	        }
	        return result;
	    }

}
